{
 "cells": [
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2024-08-22T02:45:29.986779Z",
     "start_time": "2024-08-22T02:45:29.924163Z"
    }
   },
   "source": "import numpy as np",
   "outputs": [],
   "execution_count": 1
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-08-22T02:50:33.587448Z",
     "start_time": "2024-08-22T02:50:33.571812Z"
    }
   },
   "cell_type": "code",
   "source": [
    "arr = np.array([[1, 2, 3, 4, 5, 6, 7, 8], [1, 2, 3, 4, 5, 6, 7, 8]])\n",
    "arr"
   ],
   "id": "e99aa2d570122a7e",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 2, 3, 4, 5, 6, 7, 8],\n",
       "       [1, 2, 3, 4, 5, 6, 7, 8]])"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 11
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-08-22T02:52:13.168971Z",
     "start_time": "2024-08-22T02:52:13.153345Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# split按行切分成多个矩阵\n",
    "np.split(arr, 2)"
   ],
   "id": "7372a2e202fae58d",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[array([[1, 2, 3, 4, 5, 6, 7, 8]]), array([[1, 2, 3, 4, 5, 6, 7, 8]])]"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 14
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-08-22T02:50:38.457975Z",
     "start_time": "2024-08-22T02:50:38.442401Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# axis:控制维度，0代表行（第一维）,1代表列（第二维）\n",
    "np.split(arr, 4, axis=1)"
   ],
   "id": "6cb68f1a8e2968ce",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[array([[1, 2],\n",
       "        [1, 2]]),\n",
       " array([[3, 4],\n",
       "        [3, 4]]),\n",
       " array([[5, 6],\n",
       "        [5, 6]]),\n",
       " array([[7, 8],\n",
       "        [7, 8]])]"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 13
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-08-22T02:53:49.314161Z",
     "start_time": "2024-08-22T02:53:49.298538Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# 构建向量\n",
    "arr = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])\n",
    "arr"
   ],
   "id": "b8f6e9555518f541",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12])"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 15
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-08-22T02:55:27.395916Z",
     "start_time": "2024-08-22T02:55:27.380297Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# reshape：重构\n",
    "arr1 = arr.reshape((3, 4))\n",
    "arr1"
   ],
   "id": "49495e277627535a",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 1,  2,  3,  4],\n",
       "       [ 5,  6,  7,  8],\n",
       "       [ 9, 10, 11, 12]])"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 21
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-08-22T02:54:57.706244Z",
     "start_time": "2024-08-22T02:54:57.690657Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# 获取矩阵的形状\n",
    "arr1.shape"
   ],
   "id": "a07580ad2e31ac9e",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(3, 4)"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 19
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-08-22T02:56:30.674933Z",
     "start_time": "2024-08-22T02:56:30.659307Z"
    }
   },
   "cell_type": "code",
   "source": [
    "arr1 = np.array([[1, 2, 3], [4, 5, 6]])\n",
    "arr2 = np.array([[1, 2, 3], [4, 5, 6]])"
   ],
   "id": "f9f8641c0154f46c",
   "outputs": [],
   "execution_count": 22
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-08-22T02:57:19.929522Z",
     "start_time": "2024-08-22T02:57:19.913742Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# 拼接矩阵\n",
    "# 纵向拼接\n",
    "np.vstack((arr1, arr2))"
   ],
   "id": "7aa4964d86389fa6",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 2, 3],\n",
       "       [4, 5, 6],\n",
       "       [1, 2, 3],\n",
       "       [4, 5, 6]])"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 23
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-08-22T02:57:31.722549Z",
     "start_time": "2024-08-22T02:57:31.706851Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# 横向拼接\n",
    "np.hstack((arr1, arr2))"
   ],
   "id": "a985fa8e8ad93761",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 2, 3, 1, 2, 3],\n",
       "       [4, 5, 6, 4, 5, 6]])"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 24
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-08-22T02:59:04.770659Z",
     "start_time": "2024-08-22T02:59:04.755036Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# 翻转\n",
    "arr1 = np.array([[1, 2, 3], [4, 5, 6]])"
   ],
   "id": "139f30f2ca9ee2c",
   "outputs": [],
   "execution_count": 25
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-08-22T02:59:35.632420Z",
     "start_time": "2024-08-22T02:59:35.601237Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# z左右翻转\n",
    "np.fliplr(arr1)"
   ],
   "id": "be099f9767ce470c",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[3, 2, 1],\n",
       "       [6, 5, 4]])"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 26
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-08-22T03:00:11.282195Z",
     "start_time": "2024-08-22T03:00:11.256683Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# 上线翻转\n",
    "np.flipud(arr1)"
   ],
   "id": "36d37bdafecc04fc",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[4, 5, 6],\n",
       "       [1, 2, 3]])"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 27
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-08-22T03:01:30.083131Z",
     "start_time": "2024-08-22T03:01:30.067499Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# 数学函数\n",
    "arr = [1, 2, 3, 4, 5, 6, 7, 8]"
   ],
   "id": "bd85e72e172bbf07",
   "outputs": [],
   "execution_count": 28
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-08-22T03:01:44.410588Z",
     "start_time": "2024-08-22T03:01:44.394930Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# sin\n",
    "np.sin(arr)"
   ],
   "id": "48a5f17382e24af4",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 0.84147098,  0.90929743,  0.14112001, -0.7568025 , -0.95892427,\n",
       "       -0.2794155 ,  0.6569866 ,  0.98935825])"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 29
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-08-22T03:02:02.284231Z",
     "start_time": "2024-08-22T03:02:02.268603Z"
    }
   },
   "cell_type": "code",
   "source": "np.log(arr)",
   "id": "d6fb2cc7cfaeeb75",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.        , 0.69314718, 1.09861229, 1.38629436, 1.60943791,\n",
       "       1.79175947, 1.94591015, 2.07944154])"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 30
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-08-22T03:02:25.718407Z",
     "start_time": "2024-08-22T03:02:25.702773Z"
    }
   },
   "cell_type": "code",
   "source": "np.log2(arr)",
   "id": "41acfa7f70ab72ab",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.        , 1.        , 1.5849625 , 2.        , 2.32192809,\n",
       "       2.5849625 , 2.80735492, 3.        ])"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 31
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-08-22T03:02:49.209261Z",
     "start_time": "2024-08-22T03:02:49.193638Z"
    }
   },
   "cell_type": "code",
   "source": "np.exp(arr)",
   "id": "616a6570456de103",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([2.71828183e+00, 7.38905610e+00, 2.00855369e+01, 5.45981500e+01,\n",
       "       1.48413159e+02, 4.03428793e+02, 1.09663316e+03, 2.98095799e+03])"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 32
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-08-22T03:04:15.521395Z",
     "start_time": "2024-08-22T03:04:15.505744Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# 差分\n",
    "arr = np.array([1, 4, 7, 10, 2])"
   ],
   "id": "74d5e19c1dfe8759",
   "outputs": [],
   "execution_count": 33
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-08-22T03:04:34.052745Z",
     "start_time": "2024-08-22T03:04:34.021999Z"
    }
   },
   "cell_type": "code",
   "source": "np.diff(arr)",
   "id": "6dfb8ceace2758ef",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 3,  3,  3, -8])"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 34
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-08-22T03:05:02.959102Z",
     "start_time": "2024-08-22T03:05:02.943615Z"
    }
   },
   "cell_type": "code",
   "source": [
    "arr1 = np.array([[1, 2, 3, 4], [5, 6, 7, 10]])\n",
    "arr1"
   ],
   "id": "b9ce959640df1b07",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 1,  2,  3,  4],\n",
       "       [ 5,  6,  7, 10]])"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 35
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-08-22T03:06:17.807759Z",
     "start_time": "2024-08-22T03:06:17.776514Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# 行方向\n",
    "np.diff(arr1,axis=0)"
   ],
   "id": "dbb0aad9bab6edd1",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[4, 4, 4, 6]])"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 39
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-08-22T03:06:20.027070Z",
     "start_time": "2024-08-22T03:06:20.011446Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# 列方向\n",
    "np.diff(arr1,axis=1)"
   ],
   "id": "3812c27c931f1c0f",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 1, 1],\n",
       "       [1, 1, 3]])"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 40
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-08-22T03:08:55.799829Z",
     "start_time": "2024-08-22T03:08:55.784338Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# 统计函数\n",
    "arr1 = np.array([[1, 2, 3, 4], [5, 6, 7, 10]])\n",
    "arr1\n"
   ],
   "id": "a956f656a4ee6278",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 1,  2,  3,  4],\n",
       "       [ 5,  6,  7, 10]])"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 41
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "### 全局统计函数",
   "id": "727bb0303a201f1"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-08-22T03:09:45.126604Z",
     "start_time": "2024-08-22T03:09:45.110983Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# 获取全局最大值\n",
    "np.max(arr1)"
   ],
   "id": "be26a596af77cd1b",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "10"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 45
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-08-22T03:09:43.196512Z",
     "start_time": "2024-08-22T03:09:43.180890Z"
    }
   },
   "cell_type": "code",
   "source": "np.min(arr1)",
   "id": "daf07b53fcfc243a",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 44
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-08-22T03:09:55.208528Z",
     "start_time": "2024-08-22T03:09:55.192879Z"
    }
   },
   "cell_type": "code",
   "source": "np.mean(arr1)",
   "id": "d3577510f4260b66",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4.75"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 46
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-08-22T03:10:33.989623Z",
     "start_time": "2024-08-22T03:10:33.974138Z"
    }
   },
   "cell_type": "code",
   "source": "np.std(arr1)",
   "id": "d43e0194a71b4d2a",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2.7271780286589284"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 47
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "### 指定维度统计",
   "id": "937ed567fe08a4c1"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-08-22T03:12:25.061586Z",
     "start_time": "2024-08-22T03:12:25.046100Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# 计算每行的最大值\n",
    "np.amax(arr1,axis=1)"
   ],
   "id": "400388be56f8ae14",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 4, 10])"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 48
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-08-22T03:12:44.193672Z",
     "start_time": "2024-08-22T03:12:44.178105Z"
    }
   },
   "cell_type": "code",
   "source": "np.mean(arr1,axis=1)",
   "id": "a9e652642668989c",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([2.5, 7. ])"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 49
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-08-22T03:13:10.498153Z",
     "start_time": "2024-08-22T03:13:10.482524Z"
    }
   },
   "cell_type": "code",
   "source": "np.amin(arr1,axis=0)",
   "id": "cc6524e6ece81346",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1, 2, 3, 4])"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 50
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-08-22T03:15:50.995066Z",
     "start_time": "2024-08-22T03:15:50.979440Z"
    }
   },
   "cell_type": "code",
   "source": "np.random.normal(size=(10))",
   "id": "1fba2015ddc01df1",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 0.60950987,  0.59974055, -0.75104279, -0.41596876, -0.49530253,\n",
       "       -1.489885  ,  0.80119798, -0.97650965,  0.9394087 ,  1.15068915])"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 53
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "",
   "id": "7841b23decc7636"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
